﻿using System;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using Masterduner.SourceStudio.Practices.DevelopmentLibrary.Data.Common;

namespace Masterduner.SourceStudio.Practices.DevelopmentLibrary.Utilities.DataConfiguration.Windows
{
    public partial class DatabaseAssemblyLoadWindow : Form
    {
        public string DatabaseType
        {
            get { return this.cbTypes.Text; }
        }

        public string DatabaseName
        {
            get { return this.tbName.Text; }
        }

        public DatabaseAssemblyLoadWindow()
        {
            InitializeComponent();
        }

        #region DatabaseAssemblyLoadWindow_Load
        private void DatabaseAssemblyLoadWindow_Load(object sender, EventArgs e)
        {
            this.BackColor = ColorTranslator.FromHtml("#028760");
        }
        #endregion

        #region label3_Click
        private void label3_Click(object sender, EventArgs e)
        {
            if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    Assembly assembly = Assembly.LoadFile(this.openFileDialog1.FileName);
                    Type[] types = assembly.GetTypes();
                    this.cbTypes.Items.Clear();
                    foreach (Type item in types)
                    {
                        if (item.InheritFrom<Database>())
                        {
                            this.cbTypes.Items.Add(item.AssemblyQualifiedName);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
        #endregion

        #region button1_Click
        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion
    }
}
